package tag

import (
	"context"
	"github.com/gogf/gf/v2/util/gutil"
	"zuhao-seucre/api/tag/v1"
	"zuhao-seucre/internal/dao"
	"zuhao-seucre/internal/model/vo"
	"zuhao-seucre/internal/service"
)

func (c *ControllerV1) ResourceOpLogs(ctx context.Context, req *v1.ResourceOpLogsReq) (res *v1.ResourceOpLogsRes, err error) {
	res = new(v1.ResourceOpLogsRes)
	var (
		count int
		list  []*vo.ResourceOpLog
	)
	mod := dao.TResourceOpLog.Ctx(ctx)
	mod = mod.Where(dao.TResourceOpLog.Columns().ResourceType, req.ResourceType)
	mod = mod.Where(dao.TResourceOpLog.Columns().CreatorId, service.ContextX().GetUser(ctx).UserId)
	if !gutil.IsEmpty(req.ResourceCode) {
		mod = mod.Where(dao.TResourceOpLog.Columns().ResourceCode, req.ResourceCode)
	}
	err = mod.Page(1, req.PageSize).ScanAndCount(&list, &count, false)
	res.List = list
	res.TotalCount = count
	return
}
